﻿/*
{
"状态":1,
"名称":"登录-判断密码",
"作者":"马学兵",
"创建时间":"2018-07-26",
"功能":"登录-判断密码",
"log": [
	{"date":"" , "dev" :"" , "content" : ""}
]
}
*/

set nocount on 
SET XACT_ABORT on 

declare @userid varchar(100) , @pwd varchar(100) ,@company varchar(100) , @token varchar(50)
declare @datasource  varchar(100)=''
declare @user_key int
 
set @userid = '{user}'
set @pwd = '{pwd}'
set @company = '{company}'
 
--set @userid = 'admin'
--set @pwd = '123'
--set @company = '{company}'


set @token = replace(newid(),'-','') 

INSERT INTO [dbo].[y_login](
[login_user_key],[create_time],[update_time],[token])
select user_key , getdate(), getdate(), @token
from y_user  u
where u.user_id = @userid  and u.password = @pwd

if @@rowcount =0 
	RAISERROR ('SQL:错误的用户名或密码', 16 ,1 ) ; 

	
select  @user_key=user_key  
from y_user  u
where u.user_id = @userid  and u.password = @pwd 

if @datasource<>''
set @datasource=stuff(@datasource,1,1,'')	

if @userid='admin'
set @datasource='ross_ei,ross_yue'


select user_key,user_name  ,
@datasource As datasource, @token as token
from y_user  u
where u.user_id = @userid  and u.password = @pwd 

  